#include "watchdog.h"

const int wdtTimeout = 10000;
hw_timer_t *timer = NULL;

void IRAM_ATTR resetModule() 
{
  //ets_printf("ESP32 HEAP1 %d\r\n", esp_get_free_heap_size());
  //ets_printf("reboot\n");
  Serial.printf("ESP32 HEAP1 %d\r\n",esp_get_free_heap_size());
  Serial.println("reboot");
  esp_restart();
}

void Watchdog_Init(void)
{
    timer = timerBegin(0, 80, true);                  //timer 0, div 80
    timerAttachInterrupt(timer, &resetModule, true);  //attach callback
    timerAlarmWrite(timer, wdtTimeout * 1000, false); //set time in us
    timerAlarmEnable(timer);                          //enable interrupt
}


void feed_dog(void)
{
    timerWrite(timer,0);
}